import requestApi from "../requestApi";
import { getReqParams } from "../utils";
import { toast } from "nc-lightapp-front";
import { calTotal } from '../initTemplate'

export default function searchClick(props, searchVal) {
  console.log("searchval", searchVal);
  const sendData = getReqParams(props, props.meta.getMeta());
  sendData.data.querycondition = searchVal;
  requestApi.query({
    data: sendData,
    success: (response) => {
      if(!response) {
        toast({content: '没有查到相关单据', color:'danger'})
        props.table.setAllTableData('head', {rows:[]})
        calTotal.call(this, null)
        return
      }

      response && props.table.setAllTableData('head', response.head)
      response && calTotal.call(this,response)
    },
  });
}
